package com.test.sdk.scripts.controller;

import com.test.sdk.scripts.pojo.QuartzScripts;
import com.test.sdk.scripts.service.QuartzScriptsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * @author 徒有琴
 */
@Controller
public class ScriptsController {
    @Autowired
    private QuartzScriptsService quartzScriptsService;

    @RequestMapping("index.html")
    public String index(Integer status, Model model) {
        List<QuartzScripts> scripts = quartzScriptsService.getAllScripts(status);
        model.addAttribute("scripts", scripts);
        return "index";
    }

    @RequestMapping("update.html")
    public String update(String jobClass, String cron, Integer id) {
        quartzScriptsService.update(jobClass, cron, id);
        return "redirect:index.html";
    }
    @RequestMapping("pause.html")
    public String pause(Integer id) {
        quartzScriptsService.pause(id);
        return "redirect:index.html";
    }
    @RequestMapping("resume.html")
    public String resume(Integer id) {
        quartzScriptsService.resume(id);
        return "redirect:index.html";
    }
}
